<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class Earning extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        if (method_exists($this, $request->method) && $method = $request->method) {
            return $this->$method();
        }
        $this->status = 'failed';
        $this->code = '404';
    }

    public function getItems()
    {
        return [
            'id' => $this->data->id,
            'title' => $this->data->title,
            'image' => env('APP_IMGURL') . '/model/' . $this->data->image,
            'created_at' => $this->created_at->toDateString(),
        ];
    }

    public function getEarnings()
    {
        return [
            'id' => $this->data->id,
            'title' => $this->data->title,
            'money' => $this->money,
            'created_at' => $this->created_at->toDateString(),
            'ym' => $this->created_at->toTimeString(),
        ];
    }



}
